package Thread;

//synchronized除了修饰代码块外 还可以修饰一个实例方法，或者修饰一个静态方法
class Counter{
    public int count;
    synchronized public void increse(){
        count++;
    }

}

public class Demo14 {
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Thread t1 = new Thread(()->{
            for(int i = 0; i < 50000; i++){
                counter.increse();
            }
        });
        Thread t2 = new Thread(()-> {
            for (int i = 0; i < 50000; i++) {
                counter.increse();
            }
        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println(counter.count);

    }
}
